vim.g.encoding = "utf-8"
vim.g.termencoding = "utf-8"
vim.g.fileencodings = "utf-8,ucs-bom,cp936,gb18030,big5,latin1"
vim.g.fileencoding = "utf-8"

-- 自动读写改变的文本
vim.opt.autoread = true
vim.opt.autowrite = true

vim.opt.swapfile = false -- turn off swapfile
vim.opt.backup = false

-- 突出当前行 cursor line
vim.opt.cursorline = true -- highlight the current cursor line
vim.opt.cursorcolumn = false

-- line numbers
vim.opt.relativenumber = true -- show relative line numbers
vim.opt.number = true -- shows absolute line number on cursor line (when relative number is on)

-- 共享剪贴板
vim.opt.clipboard:append("unnamedplus")
vim.opt.clipboard:prepend({ "unnamed", "unnamedplus" })
vim.g.editorconfig = true

-- 鼠标工作模式
vim.opt.mouse:append("a")

-- 撤销数据文件存储
vim.opt.undofile = true
-- persistent undo
vim.bo.undofile = true
-- opt.undodir = vim.fn.expand("$HOME/.local/share/nvim/undo")
-- vim.opt.undodir = vim.fn.expand "$HOME/.config/nvim/.tmp/undo"
-- vim.notify(os.getenv("HOME") .. "/.config/nvim/.tmp/undo")
vim.opt.undodir = vim.fn.expand(os.getenv("HOME") .. "/.config/nvim/.tmp/undo")

-- tabs & indentation
vim.opt.tabstop = 2 -- 2 spaces for tabs (prettier default)
vim.opt.softtabstop = 2 -- number of spacesin tab when editing
vim.opt.shiftwidth = 2 -- 2 spaces for indent width
vim.opt.expandtab = true -- tabs are spaces, mainly because of python
vim.opt.autoindent = true -- copy indent from current line when starting new one
vim.opt.smartindent = true

-- backspace
vim.opt.backspace = { "indent", "eol", "start" } -- allow backspace on indent, end of line or insert mode start position
vim.opt.list = true
vim.opt.listchars:append("space:·") -- "space:·"
vim.opt.listchars:append("eol:↴") -- "eol:↴"
vim.opt.listchars:append("tab:  ") -- "tab:>~"

--[[
vim.opt.listchars:append "eol:⤶"
vim.opt.listchars:append "extends:→"
vim.opt.listchars:append "precedes:←"
vim.opt.listchars:append "nbsp:■"
tab:…»■,trail:■
vim.opt.listchars:append("space:·") -- "space:·"
vim.opt.listchars:append("eol: ")   -- "eol:↴"
vim.opt.listchars:append("tab:  ")  -- "tab:>~"
vim.opt.fillchars = {
  stl = " ",
  stlnc = "-",
  msgsep = " ",
  foldopen = "",
  foldclose = "",
  fold = " ",
  foldsep = " ",
  diff = "╱",
  eob = " ",
}
]]

-- 不使用原生的底下状态栏模式显示,可以使用 lualine.nvim 插件更美观
vim.opt.showmode = true -- we are experienced, wo don't need the "-- INSERT --" mode hint

-- 编辑器左侧预留一列空间, 显示一些图标指示
vim.opt.signcolumn = "yes" -- show sign column so that text doesn't shift

-- 右侧参考线
vim.opt.colorcolumn:append("80")
vim.opt.colorcolumn:append("100")
vim.opt.colorcolumn:append("120")
vim.opt.colorcolumn:append("140")

-- Searching
vim.opt.incsearch = true -- search as characters are entered
vim.opt.hlsearch = true -- do not highlight matches
vim.opt.ignorecase = true -- ignore case when searching
vim.opt.smartcase = true -- if you include mixed case in your search, assumes you want case-sensitive

-- split windows
vim.opt.splitright = true -- split vertical window to the right
vim.opt.splitbelow = true -- split horizontal window to the bottom

-- line wrapping
vim.opt.wrap = false -- disable line wrapping

-- 可通过命令自定递增递减的字符 (默认快捷键是 Ctrl + a 递增, Ctrl + x 递减)
vim.opt.nrformats = "bin,hex,alpha"

vim.opt.foldcolumn = "1" -- '0' is not bad
vim.opt.foldenable = true
vim.opt.foldlevel = 0 -- Using ufo provider need a large value, feel free to decrease the value
vim.opt.foldlevelstart = 99

-- Finding files - Search down into subfolders
vim.opt.path:append("**")
vim.opt.wildignore:append({
  "*/node_modules/*",
  "*/target/*",
})

-- Buffer-local options
vim.opt_local.spell = true -- Enable spell checking for the current buffer

vim.opt.termguicolors = true -- Enable true color support
